import 'package:boss/color_constant.dart';
import 'package:boss/models/order_page_data.dart';
import 'package:boss/ui/page/reportForm/order/provider/order_provider.dart';
import 'package:boss/ui/page/reportForm/order/widget/order_header_bar.dart';
import 'package:boss/ui/widget/loader/loader_pull_refresh.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'order_filter_panel.dart';
import 'order_item.dart';

class OrderBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {},
      child: Consumer<OrderProvider>(
        builder: (context, orderProvider, _) {
          return LoaderPullRefresh<Order>(
            key: orderProvider.loaderPullRefreshKey,
            loadTask: orderProvider.loadMoreOrderList,
            refreshTask: orderProvider.refreshTask,
            builder: (context) {
              return CustomScrollView(
                slivers: <Widget>[
                  OrderFilterPanel(),
                  SliverToBoxAdapter(
                    child: OrderHeaderBar(
                      title: '订单明细',
                      titleStyle: TextStyle(
                        fontSize: 37.sp,
                        color: ColorConstant.ff33,
                      ),
                      orderCount: orderProvider.orderCount,
                      price: orderProvider.orderPrice,
                    ),
                  ),
                  SliverPadding(
                    padding: EdgeInsets.symmetric(horizontal: 30.w),
                    sliver: Consumer<OrderProvider>(
                      builder: (context, orderProvider, _) {
                        return SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (context, index) {
                              var current = orderProvider.orders[index];

                              return OrderItem(
                                data: current,
                                onTap: () {
                                  Navigator.pushNamed(context, '/orderDetailPage', arguments: {
                                    'unionOrderId': current.unionOrderId,
                                    'endDate': orderProvider.endTime.toString(),
                                    'startDate': orderProvider.startTime.toString(),
                                  });
                                },
                              );
                            },
                            childCount: orderProvider.orders.length,
                          ),
                        );
                      },
                    ),
                  ),
                ],
              );
            },
          );
        },
      ),
    );
  }
}
